package com.day2sockettest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class SocketTest {
    public static void main(String[] args) throws IOException {
        //创建socket，指定ip，port
        Socket socket=new Socket("127.0.0.1",8080);
        //获得键盘输入
        BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
        //获得基于Socket的输入流和输出流
        PrintWriter os=new PrintWriter(socket.getOutputStream());  //发给服务器的数量
        BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String readline;

        ClientThread ct=new ClientThread(socket);
        ct.start(); //接收服务器信息的线程

        //向服务器写数据
        while (!(readline= sin.readLine()).equals("exit")){
            os.println(readline);
            os.flush();   //发给了服务器
        }
    }
}
